package com.shangke.springbootkkyp.serview.imp;

import com.shangke.springbootkkyp.dao.AdminDao;
import com.shangke.springbootkkyp.pojo.Admin;
import com.shangke.springbootkkyp.serview.AdminSerview;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
@Slf4j
@Service
public class AdminServiewImp implements AdminSerview {

    @Autowired
    AdminDao adminDao;

    /***
     * 新增收货地址
     * @param admin
     * @return
     */
    @Override
    public Integer adminaAdd(Admin admin) {
        if(adminDao.saveByXxlSsoSessionid(admin)>0?true:false)
            return adminDao.findMaxId();
        log.error("AdminServiewImp类adminaAdd方法sql语句出现问题");
        return 0;
    }

    /**
     * 删除收货地址
     * @param adminId
     * @param xxl_sso_sessionid
     * @return
     */
    @Override
    public Boolean adminDelete(Long adminId, String xxl_sso_sessionid) {
        return adminDao.deleteByid(adminId,xxl_sso_sessionid)>0?true:false;
    }

    /**
     * 修改收货地址
     * @param id
     * @return
     */
    @Override
    public Boolean adminEdit(Long id, HashMap<String, String> hashMap, String xxlSsoSessionid) {
        return adminDao.updaterById(id,hashMap,xxlSsoSessionid)>0?true:false;
    }

    /**
     * 收货地址详情
     * @param adminId
     * @param xxl_sso_sessionid
     * @return
     */
    @Override
    public Admin adminGet(Long adminId, String xxl_sso_sessionid) {
        return adminDao.findByIdAndXxlSsoSessionid(adminId,xxl_sso_sessionid);
    }

    /**
     * 设置为是默认地址
     * @param adminId
     * @param xxl_sso_sessionid
     * @return
     * Aop后面还要查看数据库中是否是默认地址
     */
    @Override
    public Boolean truePriority(Long adminId, String xxl_sso_sessionid) {
        return adminDao.updateByIdAndXxlSsoSessionid(adminId,xxl_sso_sessionid,0)>0?true:false;
    }

    /**
     * 设置为不是默认地址
     * @param adminId
     * @param xxl_sso_sessionid
     * @return
     *
     */
    @Override
    public Boolean flasePriority(Long adminId, String xxl_sso_sessionid){
        return adminDao.updateByIdAndXxlSsoSessionid(adminId,xxl_sso_sessionid,1)>0?true:false;
    }


    /**
     * 获取默认收货地址
     * @param xxl_sso_sessionid
     * @return
     */
    @Override
    public Admin priorityGet(String xxl_sso_sessionid) {
        return adminDao.findByAdminIdAndXxlSsoSessionid(0,xxl_sso_sessionid);
    }

    /**
     * 获取收货地址列表
     * @param page
     * @param xxl_sso_sessionid
     * @return
     */
    @Override
    public List<Admin> get(Integer page, String xxl_sso_sessionid) {
        return null;
    }

}
